//
//  DemoOO.m
//  ocdemo
//
//  Created by mengchang on 2021/6/6.
//  Copyright © 2021 JIENING ZHANG. All rights reserved.
//

#import "DemoOO.h"

@interface Account : NSObject

@property (nonatomic) long                          accountID;      // 账目id，使用创建时间的时间戳，精确到秒
@property (nonatomic, copy) NSDate                  *cDate;         // 创建时间
@property (nonatomic, copy) NSDate                  *aDate;         // 账目发生时间
@property (nonatomic) float                         amount;         // 金额，单位元
@property (nonatomic, copy) NSString                *comment;       // 备注

- (NSDictionary *)infoDic;
- (instancetype)initWithInfoDic:(NSDictionary *)infoDic;
@end

@implementation Account
- (NSDictionary *)infoDic {
    return @{
        @"accountID":   @(_accountID),
        @"cDate":       _cDate?:([NSDate dateWithTimeIntervalSince1970:_accountID]),
        @"aDate":       _aDate?:([NSDate dateWithTimeIntervalSince1970:_accountID]),
        @"amount":      @(_amount),
        @"comment":     _comment ?:@""
    };
}

- (instancetype)initWithInfoDic:(NSDictionary *)infoDic {
    if (self = [super init]) {
        if(infoDic) {
            if (infoDic[@"accountID"] && [infoDic[@"accountID"] isKindOfClass:[NSNumber class]]) {
                _accountID = [(NSNumber*)(infoDic[@"accountID"]) longValue];
            }
            
            if (infoDic[@"amount"] && [infoDic[@"amount"] isKindOfClass:[NSNumber class]]) {
                _amount = [(NSNumber*)(infoDic[@"amount"]) floatValue];
            }
            
            if (infoDic[@"cDate"] && [infoDic[@"cDate"] isKindOfClass:[NSDate class]]) {
                _cDate = (NSDate*)(infoDic[@"cDate"]);
            }
            
            if (infoDic[@"aDate"] && [infoDic[@"aDate"] isKindOfClass:[NSDate class]]) {
                _aDate = (NSDate*)(infoDic[@"aDate"]);
            }
            
            if (infoDic[@"comment"] && [infoDic[@"comment"] isKindOfClass:[NSString class]]) {
                _comment = (NSString*)(infoDic[@"comment"]);
            }
        }
    }
    return self;
}
@end



@protocol AccountLoader <NSObject>

@required
- (BOOL)addAccount:(Account *)account;
- (BOOL)deleteAccount:(long)accountID;
- (BOOL)updateAccount:(Account *)account;

- (NSArray *)allAccountList;
@end



@interface WeekFileLoader : NSObject<AccountLoader>
- (BOOL)addAccount:(Account *)account;
- (BOOL)deleteAccount:(long)accountID;
- (BOOL)updateAccount:(Account *)account;

- (NSArray *)allAccountList;
@end

@implementation WeekFileLoader
- (BOOL)addAccount:(Account *)account {
    return NO;
}
- (BOOL)deleteAccount:(long)accountID {
    return NO;
}
- (BOOL)updateAccount:(Account *)account {
    return NO;
}

- (NSArray *)allAccountList {
    return nil;
}
@end



@interface SingleFileLoader : NSObject<AccountLoader>
- (BOOL)addAccount:(Account *)account;
- (BOOL)deleteAccount:(long)accountID;
- (BOOL)updateAccount:(Account *)account;

- (NSArray *)allAccountList;
@end

@implementation SingleFileLoader
- (BOOL)addAccount:(Account *)account {
    return NO;
}
- (BOOL)deleteAccount:(long)accountID {
    return NO;
}
- (BOOL)updateAccount:(Account *)account {
    return NO;
}

- (NSArray *)allAccountList {
    return nil;
}
@end



@interface AccountManager : NSObject
@property(nonatomic, strong) id<AccountLoader> accountLoader;
@end
@implementation AccountManager
@end



@implementation DemoOO
+ (void)demoLogic {
    
}
@end
